package com.zy.service;

import com.zy.web.bean.MyUserDTO;
import org.apache.velocity.Template;
import org.apache.velocity.VelocityContext;
import org.apache.velocity.app.VelocityEngine;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;

import java.io.StringWriter;
import java.util.Date;

/**
 * @program: shopping153_cloud
 * @description:
 * @author: zy
 * @create: 2025-08-31 10:26
 */
@Component
public class VelocityTemplateService {
    @Autowired
    private VelocityEngine velocityEngine;   //模板引擎
    @Autowired
    private VelocityContext context;   //模板上下文  map


    @Autowired
    @Qualifier("userLoginSuccessTemplate")
    private Template userLoginSuccessTemplate;



    public  String userLoginSuccessInfo(MyUserDTO myUserDTO){
        context.put("user",myUserDTO);
        context.put("currentDate",new Date());
        StringWriter writer = new StringWriter();
        userLoginSuccessTemplate.merge(context,writer);
        return writer.toString();
    }
}
